<template>
    <view>
        <j-cell-group>
            <template v-for="(item, index) in deviceList">
                <j-cell :key="index" :custom-prefix="false" :icon="item.devicePic" :size="96" :title="item.deviceName" :sub-title="item.description" @jftap="onBindtapDevice(item)"></j-cell>
            </template>
        </j-cell-group>
        <view class="no-message" v-if="!deviceList.length">
            <view class="img-box">
                <image src="https://statics.xmcsrv.net/weixin/noSenceData.png"></image>
            </view>
            <view class="message-text">
                <text>您尚未添加设备</text>
            </view>
        </view>
    </view>
</template>

<script>
// pages/scene/action-task/action-task.js
export default {
    data() {
        return {
            deviceList: []
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
        console.log('=== scene:action-status:onLoad:');
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        console.log('=== scene:action-status:onReady:');
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        console.log('=== scene:action-status:onShow:');
        this.getDeviceListByPage();
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
        console.log('--- scene:action-status:onHide:');
    },
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        console.log('--- scene:action-status:onUnload:');
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        // 分页查询设备列表
        getDeviceListByPage() {
            const data = {
                userGroupId: uni.getStorageSync('currentGroupId'),
                // getApp().globalData.currentGroupId,
                isAdmin: true,
                page: 1,
                limit: 999
            };
            getApp().globalData.api.getDeviceListByPage(data, (result) => {
                console.log('分页查询设备列表:', result);
                this.deviceList = result.data
            });
        },
        // 分页查询设备类型属性列表
        getDeviceTypePropListByPageForApp(device) {
            console.log(device)
            let data = {
                pid: device.pid,
                isCondition: false,
                //true表示查询条件，false表示查询动作
                page: 1,
                limit: 999
            };
            getApp().globalData.api.getDeviceTypePropListByPageForApp(data, (result) => {
                console.log('设备的属性列表：', result);
                if(result.total) {
                    uni.navigateTo({
                        url: `/jvss/pagesScene/action-status-prop/action-status-prop?device=${encodeURIComponent(JSON.stringify(device))}`
                    });
                } else {
                    uni.showToast({
                        title: "设备没有可选的属性",
                        icon: "none"
                    })
                }

            });
        },
        // 点击设备跳转回选择条件页面
        onBindtapDevice(ev) {
            console.log('点击跳转传参（设备对象）:', ev);
            let device = ev;
            this.getDeviceTypePropListByPageForApp(device)
        }
    }
};
</script>
<style scoped lang="less">
/* pages/scene/action-task/action-task.wxss */
.no-message {
    width: 240rpx;
    text-align: center;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .img-box {
        width: 180rpx;
        height: 200rpx;
        image {
            width: 100%;
            height: 100%;
        }
    }
    .message-text {
        margin-top:40rpx;
        color: #8e8e8e;
    }
}
</style>
